package com.ztgf.shopping.api.cms.template;


import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.common.utils.StrUtils;
import com.ztgf.shopping.models.bo.template.TempletPlatformRelationBO;
import com.ztgf.shopping.models.bo.template.TempletPlatformRelationSaveBO;
import com.ztgf.shopping.models.dto.template.TempletInfoDTO;
import com.ztgf.shopping.models.dto.template.TempletPlatformRelationDTO;
import com.ztgf.shopping.models.service.template.ITempletPlatformRelationService;
import com.ztgf.shopping.models.vo.template.TemplateInfoDVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 店铺模板关系  前端控制器
 * </p>
 *
 * @author YUE
 * @since 2020-05-23
 */
@RestController
@RequestMapping("/cms/templetPlatformRelation")
@Slf4j
@Api(value = "TempletPlatformRelationController",tags = "店铺模板关系块表接口")
public class TempletPlatformRelationController {
    @DubboReference
    private ITempletPlatformRelationService iTempletPlatformRelationService;

    /**
     *
     * @param id 模板id
     * @return
     */
    @ApiOperation(value = "修改平台活动页默认的加载页面",notes = "修改平台活动页默认的加载页面")
    @PostMapping("/updateActiveTemplateDefault")
    public Result updateActiveTemplateDefault(Long id){
        try {
            iTempletPlatformRelationService.updateActiveTemplateDefault(id);
        } catch (Exception e) {
            log.error(e.getMessage());
            return new Result(CodeEnum.FAIL_100008);
        }
        return new Result();
    }


    /**
     *
     * @param shopId 店铺id
     * @param templateId 模板id
     * @param type 0首页 1活动页 2商品详情页banner
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "shopId",value = "店铺id(平台传递0)",required = true,paramType = "query",dataType = "Long"),
            @ApiImplicitParam(name = "templateId",value = "模板id",required = true,paramType = "query",dataType = "Long"),
            @ApiImplicitParam(name = "type",value = "0首页 1活动页 2商品详情页banner",required = true,paramType = "query",dataType = "Integer"),
    })
    @ApiOperation(value = "修改默认的模板",notes = "修改默认的模板")
    @PostMapping("/updateTemplateDefault")
    public Result updateTemplateDefault(Long shopId,Long templateId,int type){
        try {
            iTempletPlatformRelationService.updateTemplateDefault(shopId,templateId,type);
        } catch (Exception e) {
            log.error(e.getMessage());
            return new Result(CodeEnum.FAIL_100008);
        }
        return new Result();
    }

//    @ApiOperation(value = "根据店铺id获取模板集合",notes = "根据店铺id获取模板集合")
//    @PostMapping("/getAllTemplateByShopId")
//    public Result<List<TemplateInfoDVO>> getAllTemplateByShopId(Long shopId, int type){
//        List<TemplateInfoDVO> templetInfoDTOList = iTempletPlatformRelationService.getTempletInfoListByShopId(shopId,type);
//        return new Result<>(templetInfoDTOList);
//    }
//
//    @ApiOperation(value = "添加店铺模板关系块",notes = "添加店铺模板关系块")
//    @PostMapping(value = "/insert")
//    public Result insert( TempletPlatformRelationSaveBO templetPlatformRelationSaveBO) {
//        boolean flag = iTempletPlatformRelationService.add(templetPlatformRelationSaveBO);
//        if (flag){
//            return new Result<>();
//        } else {
//            return new Result<>(CodeEnum.FAIL_100007);
//        }
//    }
//
//    @PostMapping("/save")
//    @ApiOperation(value = "保存店铺模板关系块",notes = "保存店铺模板关系块")
//    public Result save( TempletPlatformRelationSaveBO templetPlatformRelationSaveBO){
//        if(templetPlatformRelationSaveBO.getId() == null){
//            //添加
//            return  insert(templetPlatformRelationSaveBO);
//        } else {
//            return  update(templetPlatformRelationSaveBO);
//        }
//    }
//
//    @ApiOperation(value = "修改店铺模板关系块",notes = "修改店铺模板关系块")
//    @PostMapping("/update")
//    public Result update( TempletPlatformRelationSaveBO templetPlatformRelationSaveBO){
//        TempletPlatformRelationDTO templetPlatformRelationDTO = new TempletPlatformRelationDTO();
//        BeanUtils.copyProperties(templetPlatformRelationSaveBO, templetPlatformRelationDTO);
//        templetPlatformRelationDTO.setId(templetPlatformRelationSaveBO.getId());
//        boolean flag = iTempletPlatformRelationService.updateById(templetPlatformRelationDTO);
//        if (flag){
//            return new Result<>();
//        } else {
//            return new Result<>(CodeEnum.FAIL_100008);
//        }
//    }
//
//
//    @ApiOperation(value = "删除店铺模板关系块",notes = "删除店铺模板关系块")
//    @ApiImplicitParam(name = "id",value = "店铺模板关系块id",required = true,paramType = "query",dataType = "Long")
//    @PostMapping("/delete")
//    public Result delete(@RequestParam("id") Long id){
//        boolean flag = iTempletPlatformRelationService.deleteById(id);
//        if (flag){
//            return new Result<>();
//        } else {
//            return new Result<>(CodeEnum.FAIL_100009);
//        }
//    }
//
//    @PostMapping("/deleteBatch")
//    @ApiOperation(value = "批量店铺模板关系块",notes = "批量店铺模板关系块")
//    @ApiImplicitParam(name = "ids",value = "ids:以逗号隔开",required = true,paramType = "query", dataType = "String")
//    public Result deleteBatch(@RequestParam("ids") String ids){
//        if(StrUtils.isEmpty(ids)){
//            return new Result(CodeEnum.FAIL_100002 );
//        }
//        String[] arr = ids.split(",");
//        iTempletPlatformRelationService.deleteBatchIds(Arrays.asList(arr));
//        return new Result<>();
//
//    }
//
//    @PostMapping("/get")
//    @ApiOperation(value = "根据id查找",notes = "根据id查找")
//    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
//    public Result<TempletPlatformRelationDTO> get(@RequestParam("id") Long id){
//        if(id == null){
//            return new Result<>(CodeEnum.FAIL_100002 );
//        }
//        TempletPlatformRelationDTO templetPlatformRelationDTO = iTempletPlatformRelationService.selectById(id);
//        return new Result<>(templetPlatformRelationDTO);
//    }
//
//    @ApiOperation(value = "店铺模板关系块列表",notes = "店铺模板关系块列表")
//    @PostMapping("/queryPageList")
//    public Result<Page<TempletPlatformRelationDTO>> queryPageList( TempletPlatformRelationBO templetPlatformRelationBO){
//        //Wrapper<EpgMainNavigationDTO> wrapper = new EntityWrapper<>();
//        Page<TempletPlatformRelationDTO> page = new Page<>(templetPlatformRelationBO.getPageNo(), templetPlatformRelationBO.getPageSize());
//        page = iTempletPlatformRelationService.selectPage(page);
//        return new Result<>(page);
//    }

}

